<template>
	<view class="content">
		<citySelect
		@cityClick="cityClick"
		:formatName="formatName"
		:hotCity="hotCity"
		:obtainCitys="obtainCitys"
		:isSearch="true"
		ref="citys"
		@dele="deleat"
		@xgdata="xginfo"
		></citySelect>
		<view class="new_adress">
				<button @click="gonewadr" type="default">新增收货地址</button>
		</view>

	</view>
</template>

<script>
	import citySelect from "@/components/adress/city-select.vue"
	import citys from './citys.js' 
	  import requestUrl from '@/index.js';
	  import {
	  	mapMutations
	  } from 'vuex';
	export default {
		data() {
			return {
				priceList:[],
					//需要构建索引参数的名称（注意：传递的对象里面必须要有这个名称的参数）
					formatName: 'title',
					//当前城市
					activeCity: {
						id: 0,
						title: ''
					},
					qty:'',
					deliveryId:'',
					payer:'',
					orderType:'',
					numOrders:0,
					//热门城市
					// hotCity: [
					// 	{
					// 		id: 0,
					// 		title: '南京市'
					// 	},
					// 	{
					// 		id: 1,
					// 		title: '南京市'
					// 	}
					// ],
					//显示的城市数据
					obtainCitys: [
						// {
						// 	id: 0,
						// 	title: '南京'
						// },
						// {
						// 	id: 1,
						// 	title: '北京'
						// },
						// {
						// 	id: 2,
						// 	title: '天津'
						// },
						// {
						// 	id: 3,
						// 	title: '东京'
						// }
					]
				
			}
		},
		components: {
			citySelect,
		},
		async onShow() {
			
		  await this.hdshr()
			console.log('hdshr',this.obtainCitys)
		},
		
		onPullDownRefresh() {
		        this.hdshr()
				
		        setTimeout(function () {
		            uni.stopPullDownRefresh();
		        }, 1000);
		    },
		onLoad() {
			
			//动态更新数据
				//修改数据格式
				this.formatName = 'receiver'
				//修改当前城市
				//修改热门城市
				// this.hotCity = [
				// 	{
				// 		cityName: '南京',
				// 		cityCode: 110100
				// 	},
				// 	{
				// 		cityName: '北京',
				// 		cityCode: 110102
				// 	}
				// ]
				//修改构建索引数据
				
				// uni.showToast({
				// 	icon: 'none',
				// 	title: '更新数据成功',
				// 	// #ifdef MP-WEIXIN
				// 	duration: 1000,
				// 	// #endif
				// 	mask: true
				// })
			
		},
		
		methods: {
			...mapMutations(["receve",]),
			gonewadr(){
				if(!uni.getStorageSync("token")){
					uni.showModal({
					    title: '提示',
					    content: '您未登录,是否跳转到登录页',
					    success: function (res) {
					        if (res.confirm) {
					            uni.switchTab({
					            	url: '../mine/mine' 
					            })
					        } else if (res.cancel) {
					           return console.log('用户点击取消');
					        }
					    }
					});
				}else{
					uni.navigateTo({
						url: '../newAddress/newAddress' 
					})
				}
			},
			
			
		async	hdshr(){
				let res = await this.$request.get(this.$requestUrl.GET_ADRESS_URL, {
					data: {
						type:2,
						isTms:0
					}
				});
				this.obtainCitys=res
				
				this.$api.msg(res || '系统繁忙，请稍后重试')
			},
			xginfo(item) {
				const items = JSON.stringify(item.oldData)
				uni.navigateTo({
					url: '../newAddress/newAddress?data=' + items})
				
			},

			 deleat(item) {
				 
				let _that=this
				uni.showModal({
						    title: '提示',
						    content: '是否确定删除',
						    success: async function (res) {
						        if (res.confirm) {
						let res = await _that.$request.delete(_that.$requestUrl.DELETE_ADRESS_URL, {
						           data: {
						           		id: item.oldData.id
						           	}
						           });
						            _that.$api.msg(res || '系统繁忙，请稍后重试')
						            _that.obtainCitys=[]
						            _that.hdshr()
						           if(item.oldData.id==uni.getStorageSync('recever').id){
						           	uni.removeStorage({	key:'recever'})
						           }
						        } else if (res.cancel) {
						            
						        }
						    }
						});

			},
			cityClick(item){
				uni.setStorageSync('recever',item)
				// this.receve(item)
				uni.switchTab({
					url:'../index/index'
				})
			}
		}


	}
</script>

<style>
	.content {
		position: relative;
		height: 100vh;
	}

	.city-serach {
		background-color: #FFFFFF;
		padding: 16rpx 24rpx;
	}

	.city-serach input {
		height: 72rpx;
		border-radius: 36rpx;
		
		background-color: #F4F3F3;
		
		padding-left: 80rpx;
		outline: none;
		font-size: 26rpx;
	}

	.middle {
		padding: 24rpx;
	}

	

	.uni-form-item {
		margin-top: 24rpx;
	}

	.pay_type {
		display: flex;
	}

	.pay_type label {
		margin-right: 24rpx;
		font-size: 24rpx;
	}

	.pay_type label radio {
		transform: scale(0.8)
	}

	.goods_num {
		display: flex;
		margin-top: 6rpx;
		text-align: center;
	}

	.goods_num .jians {
		line-height: 48rpx;
		font-size: 26rpx;
		color: #7B7B7B;
		margin-right: 26rpx;
	}

	.biaoti {
		font-size: 32rpx;
		font-weight: 400;
		color: #2C2C2D;
	}

	.all_order {
		margin: 24rpx 0;
		font-size: 28px;
		font-weight: 400;
		color: #2C2C2D !important;
	}

	.bgz {
		background-color: #FFFFFF;
		border-radius: 16rpx;
		padding: 0 24rpx;
		margin-bottom: 24rpx;
	}

	.new_adress {
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: #FFFFFF;
		width: 100%;
		padding: 10px 24rpx;
		border-top: 1rpx solid #E1E1E1;
	}

	.new_adress button {
		width: 702rpx;
		height: 80rpx;
		background: #FF690D;
		border-radius: 40rpx;
		color: #FFFFFF;

	}

	.middle {
		margin-bottom: 100rpx;
	}
</style>
